package com.workstudy.workstudy.service.impl;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.workstudy.common.utils.NumberUtil;
import com.workstudy.common.utils.ShiroUtils;
import com.workstudy.workstudy.domain.*;
import com.workstudy.workstudy.mapper.WorkstudyAttendancesetMapper;
import com.workstudy.workstudy.mapper.WorkstudyPostMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.workstudy.workstudy.mapper.WorkstudyAttendanceMapper;
import com.workstudy.workstudy.service.IWorkstudyAttendanceService;
import com.workstudy.common.core.text.Convert;

/**
 * 考勤Service业务层处理
 * 
 * @author ws
 * @date 2021-03-28
 */
@Service
public class WorkstudyAttendanceServiceImpl implements IWorkstudyAttendanceService 
{
    @Autowired
    private WorkstudyAttendanceMapper workstudyAttendanceMapper;

    @Autowired
    private WorkstudyPostMapper workstudyPostMapper;

    @Autowired
    private WorkstudyAttendancesetMapper workstudyAttendancesetMapper;

    /**
     * 查询考勤
     * 
     * @param attendanceId 考勤ID
     * @return 考勤
     */
    @Override
    public WorkstudyAttendance selectWorkstudyAttendanceById(Long attendanceId)
    {
        return workstudyAttendanceMapper.selectWorkstudyAttendanceById(attendanceId);
    }

    /**
     * 查询考勤列表
     * 
     * @param workstudyAttendance 考勤
     * @return 考勤
     */
    @Override
    public List<WorkstudyAttendance> selectWorkstudyAttendanceList(WorkstudyAttendance workstudyAttendance)
    {
        return workstudyAttendanceMapper.selectWorkstudyAttendanceList(workstudyAttendance);
    }

    /**
     * 新增考勤
     * 
     * @param workstudyAttendance 考勤
     * @return 结果
     */
    @Override
    public int insertWorkstudyAttendance(WorkstudyAttendance workstudyAttendance)
    {
        //考勤人
        workstudyAttendance.setAttendanceBy(ShiroUtils.getLoginName());
        //获取岗位
        WorkstudyPost post = workstudyPostMapper.selectWorkstudyPostById(workstudyAttendance.getPostId());




        //工作质量
        BigDecimal gzzl = new BigDecimal(NumberUtil.toFloat( workstudyAttendance.getQuality(),100));
        //当天结算工资（当天工作时长*岗位每小时工资*工作质量）
        BigDecimal price = workstudyAttendance.getDuration().multiply(post.getPrice()).multiply(gzzl);
        workstudyAttendance.setPrice(price);
        return workstudyAttendanceMapper.insertWorkstudyAttendance(workstudyAttendance);
    }

    /**
     * 修改考勤
     * 
     * @param workstudyAttendance 考勤
     * @return 结果
     */
    @Override
    public int updateWorkstudyAttendance(WorkstudyAttendance workstudyAttendance)
    {
        return workstudyAttendanceMapper.updateWorkstudyAttendance(workstudyAttendance);
    }

    /**
     * 删除考勤对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteWorkstudyAttendanceByIds(String ids)
    {
        return workstudyAttendanceMapper.deleteWorkstudyAttendanceByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除考勤信息
     * 
     * @param attendanceId 考勤ID
     * @return 结果
     */
    @Override
    public int deleteWorkstudyAttendanceById(Long attendanceId)
    {
        return workstudyAttendanceMapper.deleteWorkstudyAttendanceById(attendanceId);
    }

    @Override
    public List<WorkstudyAttendance> selectWorkstudyAttendanceBywageId(Long wageId) {
        return workstudyAttendanceMapper.selectWorkstudyAttendanceBywageId(wageId);
    }

    @Override
    public int selectWorkstudyAttendanceByCount(WorkstudyAttendance workstudyAttendance) {
        return workstudyAttendanceMapper.selectWorkstudyAttendanceByCount(workstudyAttendance);
    }

    @Override
    public List<StatisticsRole> selectWorkstudyAttendanceByCountRoleId() {
        return workstudyAttendanceMapper.selectWorkstudyAttendanceByCountRoleId();
    }

    @Override
    public List<WorkstudyAttendance> selectWorkstudyAttendanceList2(WorkstudyAttendanceVo workstudyAttendanceVo) {
        return workstudyAttendanceMapper.selectWorkstudyAttendanceList2(workstudyAttendanceVo);
    }


}
